package itsm.isperp.module.service.task;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.task.TskInspectCiInfo;
import itsm.isperp.module.repository.task.TskInspectCiInfoMapper;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * 服务
 * 
 * @author lizx
 * @date 2015-05-11 11:51
 */
@Service
public class TskInspectCiInfoService extends BaseService<TskInspectCiInfo> {

	@Autowired
	protected TskInspectCiInfoMapper tskInspectCiInfoMapper;

	@Override
	public TskInspectCiInfoMapper getRepository() {
		return this.tskInspectCiInfoMapper;
	}

	public List<Map<String, Object>> findByCiId(String ciId) {
		JqGridRequest req = new JqGridRequest();
		req.isPageable(false);
		req.setSort("order_num", Direction.ASC);

		req.addFilterRule("ci_id", JqGridFilterRuleOp.eq, ciId);

		return this.findAllDetailByRequest(req);

	}

	public List<Map<String, Object>> findByTaskId(String taskId) {
		JqGridRequest req = new JqGridRequest();
		req.isPageable(false);
		req.setSort("order_num", Direction.ASC);

		req.addFilterRule("task_id", JqGridFilterRuleOp.eq, taskId);
		
		return this.findAllDetailByRequest(req);

	}
	public void saveAuditCi(String ids,String auditResult,String auditDate) {
		JdbcTemplate jdbcTemplate = ContextHolder
				.getSpringBean("jdbcTemplate");
		String[] tids=ids.split(",");
		String t="";
		for(int i=0;i<tids.length;i++)
		{
			t+="'"+tids[i]+"',";
		}
		ids=t.substring(0,t.length()-1);
		
		String sql = "update tsk_inspect_ci_info set task_ciaudit_result='"+auditResult+"',task_ciaudit_date='"+auditDate+"' where id in("+ids+")";
	    jdbcTemplate.update(sql);
	}

}
